/**
 * 
 */
package neptune.manager.utils;

import java.io.PrintStream;
import java.util.Arrays;

/**
 * @author Roberto Bifulco [RobertoBifulco.it] [info@robertoBifulco.it]
 * 
 */
public class DebugLog {

	private static PrintStream out = System.out;
	public static boolean debug = true;
	public static int debugLevel = 10;

	public static boolean classesSpecific = false;
	public static String[] enabledClasses = new String[0];

	public static void addRawDebugMessage(String message) {
		out.println(message);
	}

	public static void printDetailedLog(String log) {
		DebugLog.printDetailedLog(log, 1);
	}

	public static void printDetailedLog(String log, int debugLevel) {
		if (debug)
			if (DebugLog.debugLevel <= debugLevel)
				out.print(Thread.currentThread().getName() + "@"
						+ System.currentTimeMillis() + " - " + log);
	}

	public static void printDetailedLog(String log, String classSimpleName) {
		if (debug && !classesSpecific) {
			out.println(System.currentTimeMillis() + " ["
					+ Thread.currentThread().getName() + "]" + " ["
					+ classSimpleName + "] >>>>>> " + log);
		} else if (debug && classesSpecific) {
			Arrays.sort(enabledClasses);
			if (Arrays.binarySearch(enabledClasses, classSimpleName) >= 0) {
				out.println(System.currentTimeMillis() + " ["
						+ Thread.currentThread().getName() + "]" + " ["
						+ classSimpleName + "] >>>>>> " + log);
			}
		}
	}
}
